package tk.uodrad.apex.project.controller;

import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import tk.uodrad.apex.project.pojo.dto.UserLoginDTO;
import tk.uodrad.apex.project.pojo.entity.User;
import tk.uodrad.apex.project.pojo.vo.UserInfoVO;
import tk.uodrad.apex.project.service.UserService;
import tk.uodrad.apex.project.web.JsonResult;

/**
 * 说明：
 */
@Slf4j
@RestController
@RequestMapping("/user")
@Transactional
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 登录
     * @param userLoginDTO 用户登录DTO
     */
    @PostMapping("/login")
    public JsonResult<String> login(@RequestBody UserLoginDTO userLoginDTO) {
        String token = userService.login(userLoginDTO);
        return JsonResult.ok(token);
    }

    /**
     * 校验JWT
     * @param jwt jwt字符串
     */
    @GetMapping("/checkJwt")
    public JsonResult<UserInfoVO> checkLogin(@RequestParam("jwt") String jwt) {
        UserInfoVO userInfoVO = userService.checkJwt(jwt);
        return JsonResult.ok(userInfoVO);
    }
}
